CREATE SEQUENCE application_seq;

CREATE TABLE "Applications"
(
   "ID" integer NOT NULL, 
   "ApplicationName" text, 
   CONSTRAINT "PrimaryKey" PRIMARY KEY ("ID")
) WITH (OIDS=FALSE)
;

CREATE TABLE "Errors"
(
   "ErrorId" character varying(50) NOT NULL, 
   "Application" integer NOT NULL, 
   "Host" character varying(50) NOT NULL, 
   "Type" character varying(100) NOT NULL, 
   "Source" character varying(60) NOT NULL, 
   "Message" character varying(500) NOT NULL, 
   "UserName" character varying(50) NOT NULL, 
   "StatusCode" integer NOT NULL, 
   "TimeUtc" date NOT NULL, 
   "Details" text NOT NULL, 
   CONSTRAINT "Error_PKey" PRIMARY KEY ("ErrorId"), 
    FOREIGN KEY ("Application") REFERENCES "Applications" ("ID")    ON UPDATE CASCADE ON DELETE CASCADE
) WITH (OIDS=FALSE)
;

ALTER TABLE "Applications" ALTER COLUMN "ID" SET DEFAULT nextval('application_seq');
